<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<!-- 加载板块列表 -->
<sql:query var="one_level_plates" dataSource="${db}">
	select * from wx_plates order by plates_order_no
</sql:query>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->

<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->

<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

<!-- BEGIN HEAD -->
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->

<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->

<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

<!-- BEGIN HEAD -->

<head>

	<meta charset="utf-8" />

	<title>发帖</title>

	<meta content="width=device-width, initial-scale=1.0" name="viewport" />

	<meta content="" name="description" />

	<meta content="" name="author" />

	<!-- BEGIN GLOBAL MANDATORY STYLES -->

	<link href="<%=request.getContextPath() %>/AdminLogin/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>

	<link href="<%=request.getContextPath() %>/AdminLogin/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>

	<link href="<%=request.getContextPath() %>/AdminLogin/css/style-metro.css" rel="stylesheet" type="text/css"/>

	<link href="<%=request.getContextPath() %>/AdminLogin/css/style.css" rel="stylesheet" type="text/css"/>

	<link href="<%=request.getContextPath() %>/AdminLogin/css/uniform.default.css" rel="stylesheet" type="text/css"/>
	
	<script src="<%=request.getContextPath() %>/AdminLogin/js/jquery-1.4.2.min.js" type="text/javascript" charset="UTF-8"></script>
	<!-- UEDITOR BEGIN -->
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/ueditor1.3.6/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/ueditor1.3.6/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/ueditor1.3.6/lang/zh-cn/zh-cn.js"></script>

    <style type="text/css">
        .clear {
            clear: both;
        }
    </style>
    <SCRIPT type="text/javascript">
	  	//实例化编辑器
	    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	    UE.getEditor('editor');
    </SCRIPT>

	<!-- UEDITOR END -->
    <SCRIPT type="text/javascript">
    	var reSubmit = 0;
		function checkForm(){
			var content = UE.getEditor('editor').getContent();
			var title = $("#postsName"),platesId = $("#platesId");
			if(title.val() == "") title.next().children("font").html("标题不能为空");
			if(platesId.val() == "") platesId.next().children("font").html("必须选择所属板块");
			if(title.val() != "" && platesId.val() != ""){
				//document.getElementById("postingForm").submit();
				if(reSubmit == 0){
					$.post("wx!posting.action",
						{postsName:title.val(),postsContent:content,platesId:platesId.val()},
						function(re){
							if(re == "Y"){
								reSubmit = 1;
								if(confirm("发帖成功,是否继续发帖？")){
									reSubmit = 0;
									/* 清空 标题、编辑器内容 */
									title.val("");
									UE.getEditor('editor').setContent("", false);
								}else{
									/* 关闭窗口 */
									window.parent.document.getElementById("loadFrame").src = "";
								}
							}
							else if (re == "N")
								alert("发帖失败");
						}
					);
				}else if(reSubmit == 1)
					alert("请勿重复提交");
			}
	   }
	</SCRIPT>

	<!-- END GLOBAL MANDATORY STYLES -->

	<link rel="shortcut icon" href="image/favicon.ico" />

</head>

<!-- END HEAD -->
<!-- BEGIN BODY -->

<body class="page-header-fixed">

	<!-- BEGIN FORM-->

		<form action="<%=request.getContextPath() %>/wx!posting.action" class="form-horizontal" method="post" id="postingForm">

			<div class="control-group">

				<label class="control-label">
					标题
				</label>

				<div class="controls">

					<input type="text" name="postsName" id="postsName" class=""
						maxlength="500"/>

					<span class="help-inline"><FONT color="red"></FONT></span>
				</div>

			</div>
			
			<div class="control-group">

				<label class="control-label">
					所属板块
				</label>

				<div class="controls">

					<SELECT id="platesId" name="platesId">
						<option value="" selected="selected">请选择</option>
						<c:forEach items="${ one_level_plates.rows }" var="oneLevel">
							<option value="${ oneLevel.plates_id }">${ oneLevel.plates_name }</option>
						</c:forEach>
					</SELECT>

					<span class="help-inline"><FONT color="red"></FONT></span>

				</div>

			</div>

			<div class="control-group"  style="margin-right: 100px;">

				<label class="control-label">
					正文
				</label>

				<div class="controls">

					<div><script id="editor" type="text/plain" style="height:200px;"></script></div>
					
					<span class="help-inline"><font color="red"></font></span>

				</div>

			</div>
			
			<div class="form-actions">

				<button type="button" class="btn blue" onclick="checkForm()"><i class="icon-ok"></i> Save</button>

				<button type="button" class="btn" onclick="javascript:window.close();">Cancel</button>

			</div>
		</form>
	<!-- END FORM-->
</body>
</html>